<html>
<head>
<link rel="shortcut icon" href="./favicon.ico">
<link rel="stylesheet" type="text/css" href="./style.css">
<link rel="canonical" href="./Dyadic_Boolean_Operator.html">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Computes one of the 16 possible two-variable (dyadic) Boolean operations, selectable at run-time, on the `A` and `B` input words.">
<title>Dyadic Boolean Operator</title>
</head>
<body>

<p class="inline bordered"><b><a href="./Dyadic_Boolean_Operator.v">Source</a></b></p>
<p class="inline bordered"><b><a href="./legal.html">License</a></b></p>
<p class="inline bordered"><b><a href="./index.html">Index</a></b></p>

<h1>Dyadic Boolean Operator</h1>
<p>Computes one of the 16 possible two-variable (dyadic) Boolean operations,
 selectable at run-time, on the <code>A</code> and <code>B</code> input words.</p>
<p>We implement the operator by using a multiplexer differently: each
 corresponding bit from the <code>A</code> and <code>B</code> inputs, taken together as a 2-bit
 number, selects one of the bits of a 4-bit truth table input to the
 multiplexer which describes the Boolean function.</p>
<p>For example, if we take the corresponding bits of <code>A</code> and <code>B</code> as the 2-bit
 number <code>{A,B}</code> (i.e.: where the bit from A is the most-significant bit),
 then the binary truth table <code>1000</code> describes the <code>AND</code> Boolean operation,
 as only bit 3 of the truth table is set. For readability, you can include
 a <a href="./Dyadic_Boolean_Operations.html">list of the possible truth tables</a>
 before using this module.</p>
<p>This module is useful in ALU designs for data processing and in control
 logic to set expected conditions that must be met (e.g.: CPU branch logic,
 industrial process control).</p>

<pre>
`include "<a href="./Dyadic_Boolean_Operations.html">Dyadic_Boolean_Operations</a>.vh"

`default_nettype none

module <a href="./Dyadic_Boolean_Operator.html">Dyadic_Boolean_Operator</a>
#(
    parameter WORD_WIDTH = 0
)
(
    input   wire    [`DYADIC_TRUTH_TABLE_WIDTH-1:0] truth_table,
    input   wire    [WORD_WIDTH-1:0]                word_A,
    input   wire    [WORD_WIDTH-1:0]                word_B,
    output  wire    [WORD_WIDTH-1:0]                result
);

    generate
        genvar i;
        for(i = 0; i < WORD_WIDTH; i = i+1) begin: per_bit
            <a href="./Multiplexer_Binary_Behavioural.html">Multiplexer_Binary_Behavioural</a>
            #(
                .WORD_WIDTH     (1),
                .ADDR_WIDTH     (`DYADIC_SELECTOR_WIDTH),
                .INPUT_COUNT    (`DYADIC_TRUTH_TABLE_WIDTH)
            )
            Boolean_Operator
            (
                .selector       ({word_A[i],word_B[i]}),    
                .words_in       (truth_table),
                .word_out       (result[i])
            );
        end
    endgenerate

endmodule
</pre>

<hr>
<p><a href="./index.html">Back to FPGA Design Elements</a>
<center><a href="https://fpgacpu.ca/">fpgacpu.ca</a></center>
</body>
</html>

